﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：DataAccessCardModify
// 文件功能描述：人员改卡数据访问层
//
// 
// 创建标识：2012-02-16 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DbAdapter.sqldbAdapter;
using System.Data.SqlClient;

namespace DAO.WaiGaoQiao
{
    public class DataAccessCardModify
    {
        /// <summary>
        /// 获取已发卡人员信息
        /// </summary>
        /// <returns></returns>
        public DataSet SelCardModifyInfo(int pagesize, int startindex, string strquery)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                int startrow = pagesize * (startindex - 1);
                int endrow = pagesize * startindex + 1;
                string query = "select * from (select ROW_NUMBER() OVER(ORDER BY PID ASC) rownumber,* " +
                               "from Modify_PersonCard_View where 1=1 " + strquery + ") B "
                             + "where B.rownumber > " + startrow.ToString() + " and B.rownumber < " + endrow.ToString();
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }

        /// <summary>
        /// 已发卡人员数量
        /// </summary>
        /// <returns></returns>
        public int GetCardModifyCount()
        {
            sqldb db = new sqldb();
            string query = "select count(1) from Modify_PersonCard_View";
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }

        /// <summary>
        /// 根据条件获取数量
        /// </summary>
        /// <returns></returns>
        public int GetCardModifyCountWhere(string query1)
        {
            sqldb db = new sqldb();
            string query = "select count(1) from Modify_PersonCard_View where 1=1 " + query1;
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }


        /// <summary>
        /// 获取部门列表（用于绑定下拉框）
        /// </summary>
        /// <returns></returns>
        public DataSet GetdeptName()
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                string query = "select Dep_ID,deptName from DeptView order by Dep_ID";
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }

        /// <summary>
        /// 根据编号获取一条人员信息
        /// </summary>
        /// <param name="supplierNo"></param>
        /// <returns></returns>
        public DataSet GetCardModifyInfoOne(string id)
        {
            sqldb db = new sqldb();
            string query = "select * from Modify_PersonCard_View where PID = '" + id + "'";
            return db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
        }

        public int SaveCard(object[] objper)
        {
            sqldb db = new sqldb();
            SqlParameter[] parameters = {
                    new SqlParameter("@EMPNO", SqlDbType.VarChar, 20),
                    new SqlParameter("@NEW_DEPOSIT",SqlDbType.Int),
                    new SqlParameter("@NEW_EXPIREDTIME", SqlDbType.DateTime),
                    new SqlParameter("@OPERATORID", SqlDbType.VarChar,20),
					new SqlParameter("@M_RETURN",SqlDbType.Int),
                    new SqlParameter("@SubsidyCard",SqlDbType.Bit)
                    };
            parameters[0].Value = objper[0];
            parameters[1].Value = objper[1];
            parameters[2].Value = objper[2];
            parameters[3].Value = objper[3];
            parameters[4].Direction = ParameterDirection.Output;
            parameters[5].Value = objper[4];
            db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.StoredProcedure, "SP_MODICARD", parameters);
            int count = Convert.ToInt32(parameters[4].Value);
            return count;
        }
    }
}
